package com.ilink.teacherservice.controller.Screen;

import com.ilink.ilinkcommon.log.method.MethodLog;

import com.ilink.teacherservice.service.Screen.CourseStatisticsService;
import com.ilink.teacherservice.service.Screen.MajorChartService;
import com.ilink.teacherservice.service.Screen.SchoolDistributionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ilink.ilinkcommon.domain.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/teacher")
public class MajorChartController {

    @Autowired
    private MajorChartService majorChartService;

    @Autowired
    private SchoolDistributionService schoolDistributionService;

    @Autowired
    private CourseStatisticsService courseStatisticsService;

    @MethodLog("大屏数据统计")
    @GetMapping("/screen")
    public R testClass(@Param("teacherId") String teacherId) {
        // 调用 courseStatisticsService.calculateStatistics 并传入 teacherId，其他参数为 null
        List<Map<String, Object>> courseStatistics = courseStatisticsService.calculateStatistics(null, null, null, teacherId,null,null);

        // 调用其他服务获取数据
        List<Map<String, Object>> majorNumData = majorChartService.getMajorChartNum();
        List<Map<String, Object>> schoolNumData = schoolDistributionService.SchoolDistribution();

        // 整合数据
        List<List<Map<String, Object>>> data = new ArrayList<>();
        data.add(courseStatistics);
        data.add(majorNumData);
        data.add(schoolNumData);

        // 判断数据是否存在
        if (!data.isEmpty()) {
            return R.ok(data);
        } else {
            return R.error("未找到对应数据");
        }
    }

    @MethodLog("大屏数据刷新")
    @GetMapping("/screen/refresh")
    public R refreshScreen(@Param("teacherId") String teacherId, @Param("courseId") Long courseId, @Param("chapterId") Long chapterId,@Param("fileId") Long fileId,@Param("time") Integer time,@Param("type") String type){
        List<Map<String, Object>> courseStatistics = courseStatisticsService.calculateStatistics(courseId, chapterId, fileId, teacherId, time, type);
        return R.ok(courseStatistics);
    }
}
